<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\setting;

use app\adminapi\services\setting\AttachmentCateService;
use app\adminapi\validate\setting\AttachmentValidate;
use kitego\base\BaseController;
use kitego\enums\AttachmentCategoryEnum;
use think\App;

class AttachmentCateController extends BaseController
{
    public array $safeAction = [];

    private AttachmentCateService $service;

    public function __construct(App $app, AttachmentCateService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**
     * 附件分类列表
     */
    public function attachmentCategoryList()
    {
        if (empty($this->params['type']) || !in_array($this->params['type'], AttachmentCategoryEnum::all())) exception('附件分类类型错误');

        return $this->service->attachmentCategoryList($this->params['type']);
    }

    /**
     * 附件分类新增
     */
    public function attachmentCategoryAdd()
    {
        Validate(AttachmentValidate::class)->scene('attachmentCategoryAdd')->check($this->params);

        return $this->service->attachmentCategoryAdd($this->params['name'], $this->params['pid'], $this->params['type']);
    }

    /**
     * 附件分类重命名
     */
    public function attachmentCategoryRename()
    {
        Validate(AttachmentValidate::class)->scene('attachmentCategoryRename')->check($this->params);

        return $this->service->attachmentCategoryRename($this->params['id'], $this->params['name']);
    }

    /**
     * 附件分类删除
     */
    public function attachmentCategoryDelete()
    {
        Validate(AttachmentValidate::class)->scene('attachmentCategoryDelete')->check($this->params);

        return $this->service->attachmentCategoryDelete($this->params['id']);
    }
}